package com.neusoft.elm.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.neusoft.elm.po.Admin;
import com.neusoft.elm.util.DBUtil;

public class AdminDaoImpl implements AdminDao {
	private Connection con=null;
	private PreparedStatement pst=null;
	private ResultSet rs=null;
	//声明 增删改查 供Dao层方法使用
	@Override
	public Admin getAdminByNameByPass(String adminName, String password) {
		Admin admin=null;//指向空指针，最后查不出数据，则为空指针
		String sql="select * from admin where adminName=? and password=?";
		try {
			con=DBUtil.getConnection();//获取数据库连接
			pst=con.prepareStatement(sql);//获取执行SQL对象
		    pst.setString(1,adminName);
		    pst.setString(2,password);
		    rs = pst.executeQuery();
		    if(rs.next()) {
		    	//把数据库的表数据映射成java对象数据
		    	admin=new Admin();
		    	admin.setAdminId(rs.getInt("adminId"));
		    	admin.setAdminName(rs.getString("adminName"));
		    	admin.setPassword(rs.getString("password"));
		    }
		}catch(SQLException e) {
			e.printStackTrace();
		}finally {
			//释放资源
			DBUtil.close(rs, pst, con);
		}
		
		return admin;
	}
	

}
